import {sm2} from 'sm-crypto'
import CryptoJS from 'crypto-js'

// 加密
export function doEncrypt(formData, publicKey) {
    console.log('this.publicKey::', publicKey);
    if (typeof formData !== 'string') {
        formData = JSON.stringify(formData)
    }
    const encryptData = sm2.doEncrypt(formData, publicKey)
    return encryptData
}

//解密
export function doDecrypt(encryptData, privateKey) {
    if (typeof encryptData !== 'string') {
        encryptData = JSON.stringify(encryptData)
    }
    let decryptData = sm2.doDecrypt(encryptData, privateKey)
    return decryptData
}

export function sha256(data) {
    return CryptoJS.SHA256(data).toString()
}
